package com.cskaoyan.controller;

import com.cskaoyan.bean.PO.MarketCategory;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:商品类目
 * @author:刘杰
 * @create: 2022-08-13 14:12
 */
@RestController
@RequestMapping("admin/category")
public class AdminCategoryController {

    @Autowired
    AdminCategoryService adminCategoryService;

    /**
     * 返回商品类目列表
     * @return
     */
    @RequiresPermissions("admin:category:list")
    @RequestMapping("list")
    public BaseRespVo list() {
        CommonData list = adminCategoryService.list();
        return BaseRespVo.ok(list);
    }

    /**
     * 编辑商品类目
     * @param marketCategory
     * @return
     */
    @RequiresPermissions("admin:category:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketCategory marketCategory) {
        adminCategoryService.update(marketCategory);
        return BaseRespVo.ok(null);
    }

    /**
     * 增加商品类目
     * @param marketCategory
     * @return
     */
    @RequiresPermissions("admin:category:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketCategory marketCategory) {
        MarketCategory data = adminCategoryService.create(marketCategory);
        return BaseRespVo.ok(data);
    }

    /**
     * 删除商品类目
     * @param marketCategory
     * @return
     */
    @RequiresPermissions("admin:category:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketCategory marketCategory) {
        adminCategoryService.delete(marketCategory);
        return BaseRespVo.ok(null);
    }

    /**
     * 返回一级类目
     * @return
     */
    @RequestMapping("l1")
    public BaseRespVo l1() {
         CommonData l1 = adminCategoryService.l1();
        return BaseRespVo.ok(l1);
    }

}
